package com.example.thegreatwall.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信支付配置
 */
@Configuration
public class WxPayConfiguration {

    @Value("${wx.pay.appId}")
    private String appId;

    @Value("${wx.pay.mchId}")
    private String mchId;

    @Value("${wx.pay.mchKey}")
    private String mchKey;

    @Value("${wx.pay.notifyUrl}")
    private String notifyUrl;

    @Bean
    public WxPayConfig wxPayConfig() {
        WxPayConfig config = new WxPayConfig();
        config.setAppId(appId);
        config.setMchId(mchId);
        config.setMchKey(mchKey);
        config.setNotifyUrl(notifyUrl);
        config.setTradeType("JSAPI"); // 小程序支付方式
        return config;
    }

    @Bean
    public WxPayService wxPayService(WxPayConfig wxPayConfig) {
        WxPayService service = new WxPayServiceImpl();
        service.setConfig(wxPayConfig);
        return service;
    }
}